<?php
/**
	後臺訂單處理類
	@author xiaoming<maixiaoming@9qi.cn>
*/
class OrderAction extends BaseAction 
{
	
    /**
		定义空操作
	*/
	public function _empty()
	{
		
		$this->_pageNotFound();
	}
	
	public function index()
	{
		$Order = M('order');
	
		import("ORG.Util.Page"); // 导入分页类
		$status = (isset($_GET['status']) && in_array(intval($_GET['status']),array(1,2,3))) ? $_GET['status'] : '';
		$condition = '';
		if(!empty($status)) $condition .= "status='$status'";
		$count = $Order->where($condition)->count();
		$Page = new Page($count,10);
		$show = $Page->show(); // 分页显示输出
		$orders = $Order->where($condition)
						->limit($Page->firstRow.','.$Page->listRows)->select();
		
		$this->assign('orders',$orders);
		$this->assign('page',$show);
		$this->assign('nav', 'order');
		$this->display();
		
	}
	
	/**
		查看訂單詳情
	*/
	public function view() 
	{
		$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
		if(!empty($id)) {
			$Order = M('order');
			$result = $Order->where("o_id=$id")->find();
			if($result) {
				$this->assign('order',$result);
				$this->assign('nav', 'order');
				$this->display();
			} else {
				$this->redirect('index', array(), 3, '無此訂單！');
			}
		} else {
			$this->redirect('index');
		}
	}
	
	/**
		表單提交處理程序
	*/
	public function action()
	{
		$Order = M('order');
		$Order->create();
		$o_id = $_POST['id'];
		if($Order->where("o_id=$o_id")->save()) {
			echo "<script>alert('更新成功！');</script>";
			$this->redirect('index');
			
		}
	
	}
}